import { ref } from "vue";

import type { PlusColumn, FieldValues } from "plus-pro-components";

export function useEmail() {
  const email_state = ref<FieldValues>({
    mail_type: "",
    mail_smtp_host: "",
    mail_smtp_port: "",
    mail_smtp_user: "",
    mail_smtp_pass: "",
    mail_verify_type: "",
    mail_from: ""
  });
  const email_rules = {
    mail_type: [
      {
        required: true,
        message: "请选择类型"
      }
    ],
    mail_smtp_host: [
      {
        required: true,
        message: "请输入SMTP服务器"
      }
    ],
    mail_smtp_port: [
      {
        required: true,
        message: "请输入端口"
      }
    ],
    mail_smtp_user: [
      {
        required: true,
        message: "请输入用户名"
      }
    ],
    mail_smtp_pass: [
      {
        required: true,
        message: "请输入密码"
      }
    ],
    mail_verify_type: [
      {
        required: true,
        message: "请选择验证方式"
      }
    ],
    mail_from: [
      {
        required: true,
        message: "请输入发件人"
      }
    ]
  };

  const email_columns: PlusColumn[] = [
    {
      label: "邮件发送方式",
      width: 120,
      labelWidth: 130,
      prop: "mail_type",
      valueType: "select",
      tooltip: "邮件发送方式",
      options: [
        {
          label: "SMTP",
          value: "smtp"
        }
      ]
    },
    {
      label: "SMTP服务器",
      width: 120,
      labelWidth: 130,
      prop: "mail_smtp_host",
      valueType: "copy",
      tooltip: "请输入SMTP服务器"
    },
    {
      label: "SMTP端口",
      width: 200,
      labelWidth: 130,
      prop: "mail_smtp_port",
      valueType: "copy",
      tooltip: "请输入SMTP端口"
    },
    {
      label: "SMTP用户名",
      width: 200,
      labelWidth: 130,
      prop: "mail_smtp_user",
      valueType: "copy",
      tooltip: "请输入SMTP用户名"
    },
    {
      label: "SMTP密码",
      width: 200,
      labelWidth: 130,
      prop: "mail_smtp_pass",
      valueType: "copy",
      tooltip: "请输入SMTP密码"
    },
    {
      label: "SMTP验证方式",
      labelWidth: 130,
      prop: "mail_verify_type",
      valueType: "radio",
      options: [
        {
          label: "无",
          value: 0
        },
        {
          label: "TLS",
          value: 1
        },
        {
          label: "SSL",
          value: 2
        }
      ]
    },
    {
      label: "发件人邮箱",
      width: 200,
      labelWidth: 130,
      prop: "mail_from",
      valueType: "copy",
      tooltip: "请输入发件人邮箱"
    }
  ];

  const email_handleChange = (values: FieldValues, prop: PlusColumn) => {
    console.log(values, prop, "change");
  };
  const email_handleSubmit = (values: FieldValues) => {
    console.log(values, "Submit");
  };
  const email_handleSubmitError = (err: any) => {
    console.log(err, "err");
  };
  const email_handleReset = () => {
    console.log("handleReset");
  };

  const email_sendtext = () => {
    console.log("sendtext");
  };

  return {
    email_state,
    email_rules,
    email_columns,
    email_handleChange,
    email_handleSubmit,
    email_handleSubmitError,
    email_handleReset,
    email_sendtext
  };
}
